package com.zhang.mysql.common.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.beans.Transient;
import java.io.Serializable;

/**
 * 深圳金雅福控股集团有限公司
 *
 * @author zhangfanjun
 * @date 2021/11/17
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class PageReqDTO implements Serializable {
    private static final int version = 22;
    private static final String ASC = "asc";
    private static final String DESC = "desc";

    /**
     * 页码
     */
    public long pageNum = 1;
    /**
     * 每页记录数
     */
    public long pageSize = 10;
    /**
     * 排序字段
     */
    public String orderBy = "createTime";
    /**
     * 排序类型：1升序，非1降序（2：降序）
     */
    public int sort;

    public PageReqDTO(long pageNum, long pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    @Transient
    public String getSortOrder() {
        return this.sort == 1 ? ASC : DESC;
    }
}
